package net.qhzw.geologr5.gis.service.system;


import net.qhzw.geologr5.gis.service.system.component.FileTemplate;
import org.apache.http.entity.ContentType;
import org.csource.common.MyException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

@SpringBootTest
@RunWith(SpringRunner.class)
public class FastdfsTest2 {


    @Autowired
    private FileTemplate fileTemplate;

    @Test
    public void upload() throws IOException, MyException {
        String path = "D://OIP-C.jpg";
        //file转 multipartFile
        File file = new File(path);
        FileInputStream inputStream = new FileInputStream(file);
        MultipartFile multipartFile = new MockMultipartFile(file.getName(), file.getName(),
                ContentType.APPLICATION_OCTET_STREAM.toString(), inputStream);

        String s = fileTemplate.uploadFile(multipartFile);
        System.out.println("上传后的路径:" + s);

    }


}
